package keeto.com.vn.classified.task;

import java.io.IOException;

import keeto.com.vn.classified.core.ClassifiedCore;
import keeto.com.vn.classified.core.ClassifiedListener;
import keeto.com.vn.classified.network.IProtocol;
import keeto.com.vn.classified.request.CommentRequestProduct;
import keeto.com.vn.classified.response.CommentResponseProduct;

import org.apache.http.client.ClientProtocolException;
import org.json.JSONException;


public class TaskCommentProduct extends AbstractTask{
	private String itemId;
	
	public TaskCommentProduct(ClassifiedListener listener, ClassifiedCore core, String itemId) {
		super(listener, core);
		this.itemId = itemId;
	}

	@Override
	public void run() throws ClientProtocolException, JSONException, IOException {
		CommentRequestProduct request = new CommentRequestProduct();
		request.setAuthkey(authKey);
		request.setItemId(itemId);
		CommentResponseProduct response = json.getCommentProduct(request);
		
		for (ClassifiedListener listener : listeners) {
			listener.finishGetCommentProduct(response.getReturnCode(), response.getDescription(), response.getListComment(), response.getListofRating(),response.getArrRating());
		}
	}

	@Override
	public void timeoutCallback() {
		for (ClassifiedListener l : core.copyAndReconstructListeners(listener)) {
			l.finishGetCommentProduct(IProtocol.STATUS_CODE_CONNECTION_TIMEOUT_502, null, null,null,null);
		}
	}

}
